home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib2to3 / fixes / fix_itertools_imports.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.5 KB  |  52 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. ''' Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) '''
  5. from  import fixer_base
  6. from fixer_util import BlankLine
  7.  
  8. class FixItertoolsImports(fixer_base.BaseFix):
  9.     PATTERN = "\n              import_from< 'from' 'itertools' 'import' imports=any >\n              " % locals()
  10.     
  11.     def transform(self, node, results):
  12.         imports = results['imports']
  13.         if not imports.children[:]:
  14.             pass
  15.         children = [
  16.             imports]
  17.         for child in children:
  18.             if not hasattr(child, 'value'):
  19.                 continue
  20.             
  21.             if child.value in ('imap', 'izip', 'ifilter'):
  22.                 child.value = None
  23.                 child.remove()
  24.                 continue
  25.             if child.value == 'ifilterfalse':
  26.                 node.changed()
  27.                 child.value = 'filterfalse'
  28.                 continue
  29.         
  30.         if not imports.children[:]:
  31.             pass
  32.         children = [
  33.             imports]
  34.         remove_comma = True
  35.         for child in children:
  36.             if remove_comma and getattr(child, 'value', None) == ',':
  37.                 child.remove()
  38.                 continue
  39.             remove_comma ^= True
  40.         
  41.         if unicode(children[-1]) == ',':
  42.             children[-1].remove()
  43.         
  44.         if not imports.children or getattr(imports, 'value', None):
  45.             p = node.get_prefix()
  46.             node = BlankLine()
  47.             node.prefix = p
  48.         
  49.         return node
  50.  
  51.  
  52.